'use strict';

module.exports = app => {
  const { STRING, INTEGER, TEXT, DATE } = app.Sequelize;

  const Post = app.model.define('post', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    title: { type: STRING(100), allowNull: false, comment: '标题' },
    images: { type: TEXT, comment: '图片集，JSON格式' },
    content: { type: TEXT, allowNull: false, comment: '内容' },
    memberId: { type: INTEGER, allowNull: false, comment: '发帖会员ID' },
    status: { type: INTEGER, defaultValue: 1, comment: '状态：1-正常，0-删除' },
    createdAt: DATE,
    updatedAt: DATE,
  });

  Post.associate = function() {
    app.model.Post.belongsTo(app.model.Member, { foreignKey: 'memberId', as: 'member' });
  };

  return Post;
};
